export function useCache() {
  const cache = new Map()

  const setCache = (key, data, duration) => {
    cache.set(key, {
      data,
      timestamp: Date.now(),
      duration
    })
  }

  const getCache = (key) => {
    const item = cache.get(key)
    if (!item) return null

    const isExpired = Date.now() - item.timestamp > item.duration
    if (isExpired) {
      cache.delete(key)
      return null
    }

    return item.data
  }

  const clearCache = (key) => {
    if (key) {
      cache.delete(key)
    } else {
      cache.clear()
    }
  }

  return {
    cache,
    setCache,
    getCache,
    clearCache
  }
} 